import baseURL from '@/http'
import tip from '@/utils/tip'

export default async (data, method = 'GET', url, load = true, loadTitle) => {
    load ? tip.loading(loadTitle) : '';
    let requstPrimise = new Promise(function(resolve, reject) {
        wx.request({
            url: baseURL + url,
            data,
            method,
            success: function(res) {
                tip.loaded();
                if (res.statusCode != 200) {
                    tip.error('网络错误')
                    resolve({
                        error: 'The server is busy',
                        code: 500
                    });
                }
                resolve(res.data)
                return
            },
            fail: function(res) {
                tip.toast('网络错误，请手动删除小程序后重新搜索进入', "none", 5000)
                resolve('error:', res);
            }
        })
    })
    return requstPrimise
}